//
//  AY_BookQdAlertView.m
//  AiYue
//
//  Created by boWen on 2023/11/13.
//

#import "AY_BookQdAlertView.h"

@interface AY_BookQdAlertView ()
@property (nonatomic, strong) UIView * bg_View;
@property (nonatomic, strong) UIImageView * bgTopImgView;
@property (nonatomic, strong) UIImageView * jinbiImgView;
@property (nonatomic, strong) UILabel * jinbLabel;
@property (nonatomic, strong) UIButton* sureBtn;
@end

@implementation AY_BookQdAlertView


- (instancetype)initWithFrame:(CGRect)frame {
    if([super initWithFrame:frame]) {
        [self initWithAllUI];
    }
    return self;
}


- (void)initWithAllUI {
    self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.4];
    UIView *bgView = [AYTool createViewWithFrame:CGRectZero andBg:[UIColor clearColor] andRadius:0 andAddSubView:self];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    bgView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapGest = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGestAction)];
    [bgView addGestureRecognizer:tapGest];
    
    self.bg_View = [AYTool createViewWithFrame:CGRectZero andBg:[UIColor clearColor] andRadius:YNUM(16) andAddSubView:self];
    [self.bg_View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.centerY.equalTo(self);
        make.height.mas_offset(YNUM(326));
        make.width.mas_offset(YNUM(300));
    }];
    
    self.bgTopImgView = [AYTool createImageViewWithFrame:CGRectZero andImage:YImage(@"icon_qdcg_alert.png") andBg:[UIColor clearColor] andRadius:0.0 andAddSubView:self];
    [self.bgTopImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bg_View);
        make.right.equalTo(self.bg_View);
        make.left.equalTo(self.bg_View);
        make.height.mas_offset(YNUM(178));
    }];
    
    UIView * downV = [AYTool createViewWithFrame:CGRectZero andBg:[UIColor whiteColor] andRadius:YNUM(16) andAddSubView:self.bg_View];
    [downV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bg_View).offset(YNUM(100));
        make.bottom.equalTo(self.bg_View);
        make.right.equalTo(self.bg_View);
        make.left.equalTo(self.bg_View);
    }];
    
    self.sureBtn = [AYTool createButtonWithFrame:CGRectZero andTitle:@"金币翻倍（X2）" andFont:[UIFont boldSystemFontOfSize:16] andTitleColor:[UIColor whiteColor] andBg:COLOR(@"#F76B30") andImage:nil andBgImage:nil andTarget:self andAction:@selector(handleJinBiAction) andRadius:YNUM(21) andAddSubView:downV];
    [self.sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(downV).offset(YNUM(-27));
        make.left.equalTo(downV).offset(YNUM(16));
        make.right.equalTo(downV).offset(YNUM(-16));
        make.height.mas_offset(YNUM(42));
    }];
    self.sureBtn.backgroundColor = [AYTool customJianBianColorWithColor0:COLOR(@"#FF9760") withColor1:COLOR(@"#F76B30") withFrame:CGSizeMake(YNUM(268), YNUM(42)) withType:0];

    
    self.jinbiImgView = [AYTool createImageViewWithFrame:CGRectZero andImage:YImage(@"icon_qd_alert.png") andBg:[UIColor clearColor] andRadius:0.0 andAddSubView:downV];
    [self.jinbiImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.mas_offset(YNUM(63));
        make.bottom.equalTo(self.sureBtn.mas_top).offset(YNUM(-22));
        make.centerX.equalTo(downV).offset(YNUM(-65));
    }];
    self.jinbLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#F86923") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(26)] andLines:1 andRadius:0 andAddSubView:downV];
    [self.jinbLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.jinbiImgView.mas_right).offset(YNUM(8));
        make.centerY.equalTo(self.jinbiImgView);
        make.height.mas_equalTo(YNUM(38));
    }];
  
}

- (void)tapGestAction
{
    [self dismissPopView];
}

- (void)setBottomTitle:(NSString *)bottomTitle
{
    _bottomTitle = bottomTitle;
    [self.sureBtn setTitle:bottomTitle forState:UIControlStateNormal];
}

// 显示View
- (void)showPopView{
    [[[UIApplication sharedApplication] windows].firstObject addSubview:self];
}

// 隐藏View
- (void)dismissPopView{
    if(self) {
        [self removeFromSuperview];
    }
}

- (void)setRewordjib:(NSString *)rewordjib {
    _rewordjib = rewordjib;
    if (!self.extProperty) {
        self.jinbLabel.text = [NSString stringWithFormat:@"%@金币", kStringUtils(_rewordjib)];
    }else{
        self.jinbLabel.text = _rewordjib;
    }
    
}

- (void)handleJinBiAction {
    [self dismissPopView];
    if(self.fanbeiBlock) {
        self.fanbeiBlock();
    }
}

@end
